package cn.gok.handle;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class AutoUpdateHandle implements MetaObjectHandler {
    //实现自动填充处理器
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("insert填充----");
        //插入时候的填充策略
        this.setFieldValByName("createTime",new Date(),metaObject);
        this.setFieldValByName("updateTime",new Date(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("update填充----");
        //更新时候的填充策略
        this.setFieldValByName("updateTime",new Date(),metaObject);
    }
}
